const mysql = require('mysql2')
const { MYSQL_HOST, MYSQL_PORT, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD } = require('./config')
// 1.创建数据库连接池
const connections = mysql.createPool({
  host: MYSQL_HOST,
  port: MYSQL_PORT,
  database: MYSQL_DATABASE,
  user: MYSQL_USER,
  password: MYSQL_PASSWORD,
  connectionLimit: 10,
})
connections.getConnection((err, conn) => {
  if (err) {
    console.log('数据库连接失败', err)
  } else {
    conn.connect(err => {
      if (err) {
        console.log('数据库连接失败', err)
      } else {
        console.log('数据库连接成功')
      }
    })
  }
})
module.exports = connections.promise()
